Xbasic

STRITRAN Function

Syntax

Output_String as C = STRITRAN(C character,C substring,[C replacement,[N start_pos,[N occurrences[,N every]]]])

Arguments

Output_String

The character string produced by the replacement operation.

character

The character string to search.

substring

The string to find in the Search_String.

replacement

Optional. Default = "" (NULL). The string that replaces the Find_String.

start_pos

Optional. Default = 1. Specifies which (and subsequent) occurrences will be replaced. A value N for the optional Start_Position begins the replacement at the N th occurrence of Find_String. Numeric

occurrences

Optional. Default = All. Specifies the maximum number of occurrences of Find_String to replace with Replace_String. Numeric

every

Optional. Default = 1. Specifies the interval between replacements. Numeric

Description

Replaces each occurrence of a string with another - compare is case insensitive.

Discussion

Replaces every occurrence of substring in string with a replacement string. STRITRAN() is not case sensitive. Note : You can use STRITRAN() with memo fields.

Example

stritran("The Road Not Traveled", "Traveled", "Paved") -> "The Road Not Paved"
stritran("I much prefer cats", "cats", "dogs") -> "I much prefer dogs"

You can use STRITRAN() to remove a specific substring from anywhere within another character string. For example, to index a field containing titles, without the article "The", you might use the following expression:

stritran(EVENT, "The ", "", 1, 1) -> "Kentucky Derby" if EVENT stores "The Kentucky Derby".

This then places "Kentucky Derby" near the other events starting with "K" instead of with the events starting with "T". The following example replaces every second letter "e" in the search string.

dim string as C
string = "this is the number one replacement function"
? stritran(string, "e", "|", 1, 99, 2)
= "this is th| number on| replac|ment function"

Expressions cannot exceed 1024 characters. as a result, it can be impossible to insert a variable into a long string with character addition. This example shows how to insert a variable into a long character string by replacing a unique placeholder ( myvar ).

a = 
...long string... myvar ...long string... 
%str%
a = stritran(a, myvar, variable)

See Also